import java.util.Arrays;
import java.util.Scanner;

public class code {
    //8.存在连续三个奇数的数组
    public static boolean threeOdd(int [] array) {
        for (int i = 0; i < array.length-2; i++) {
            if(array[i]%2==1&&array[i+1]%2==1&&array[i+2]%2==1)
                return true;
        }
        return false;
    }

    public static void main8(String[] args) {
        int [] array = {1,2,34,3,4,5,7,23,12};
        boolean ret = threeOdd(array);
        System.out.println(ret);
    }


    //7.在数组中出现次数 大于 ⌊ n/2 ⌋ 的元素
    public static int countMax(int [] array) {
        for (int i = 0; i < array.length; i++) {
            int count=0;
            for (int j = 0; j < array.length; j++) {
                if(array[j]==array[i])
                    count++;
            }
            if(count>(array.length/2))
               return array[i];
        }
        return -1;
    }
    public static void main7(String[] args) {
        int [] array ={2,2,1,1,1,2,2};
        int ret = countMax(array);
        System.out.println(ret);
    }


    //6.找出那个只出现了一次的元素
    public static int findOne(int [] array) {
        int ret =0;
        for (int i = 0; i < array.length; i++) {
            ret ^= array[i];
        }
        return ret;
    }
    public static void main6(String[] args) {
        int [] array = {4,6,2,6,2};
        int ret =findOne(array);
        System.out.println(ret);
    }


    //5.给定一个整数数组 nums 和一个整数目标值 target，请你在该数组中找出 和为目标值 target 的那 两个 整数，并返回它们的数组下标
    public static int [] indexMax(int [] array,int target) {
        int ret [] =new int[2];
        for (int i = 0; i < array.length-1; i++) {
            for (int j = i+1; j < array.length; j++) {
                if(array[i]+array[j]==target) {
                    ret[1] = i;
                    ret[0] = j;
                }
            }
        }
        return ret;
    }
    public static void main5(String[] args) {
        int [] array = {2,7,11,15};
        Scanner sc=new Scanner(System.in);
        int target= sc.nextInt();
        int [] ret =indexMax(array,target);
        System.out.println(Arrays.toString(ret));

    }


    //4.调整数组顺序使得奇数位于偶数之前。调整之后，不关心大小顺序
    public static int [] adjust(int [] array) {
        int j = 0;
        int k = array.length-1;
        int [] copy =new int[array.length];
        for (int i = 0; i < array.length; i++) {
            if(array[i]%2==1) {
                copy[j++]=array[i];
            }
            else {
                copy[k--]=array[i];
            }
        }
        return copy;
    }
    public static void main4(String[] args) {
        int [] array ={1,2,3,4,5,6};
        int [] ret=adjust(array);
        System.out.println(Arrays.toString(ret));
    }


    //3.实现一个方法 sum, 以数组为参数, 求数组所有元素之和
    public static int sum(int [] array) {
        int sum=0;
        for (int i = 0; i < array.length; i++) {
            sum +=array[i];
        }
        return sum;
    }
    public static void main3(String[] args) {
        int [] array ={1,2,3};
        int ret = sum(array);
        System.out.println(ret);
    }


    //2.实现一个方法 transform, 以数组为参数, 循环将数组中的每个元素 乘以 2 , 并设置到对应的数组元素上. 例如 原数组为 {1, 2, 3}, 修改之后为 {2, 4, 6}
    public static void mul(int [] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] = array[i] *2;
        }
    }
    public static void main2(String[] args) {
        int [] array ={1,2,3};
        System.out.println(Arrays.toString(array));
        mul(array);
        System.out.println(Arrays.toString(array));
    }

    //1.创建一个 int 类型的数组, 元素个数为 100, 并把每个元素依次设置为 1 - 100
    public static void main1(String[] args) {
        int [] array=new int[100];
        for (int i = 0; i < array.length; i++) {
            array[i]= i + 1;
        }
        System.out.println(Arrays.toString(array));
    }
}
